package com.qing.demo.netty.demo1.bio.server;

import cn.hutool.log.Log;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.Charset;
import java.util.logging.Logger;

/**
 * @author caozhipeng
 * @date 2025/7/22
 */
public class BioServer extends Thread{

    private Logger logger= Logger.getLogger(BioServer.class.getName());


    private ServerSocket serverSocket;


    @Override
    public void run() {
        try {
            serverSocket=new ServerSocket(7379);
            logger.info("启动服务器成功!");
            while (true){
                Socket socket=serverSocket.accept();
                logger.info("有新的连接加入!");
                BioServerHandler handler=new BioServerHandler(socket, Charset.forName("UTF-8"));
                handler.start();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        BioServer bioServer=new BioServer();
        bioServer.start();
    }
}
